<template>
  <div v-if="show" class="im-top">
    <p>
      商家不在线时，系统将安排小店客服为您服务！
    </p>
    <div class="right">
      {{ `${countDown}s`
      }}<span class="close" @click.stop="closeTimer">关闭</span>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      show: true,
      countDown: 10,
      timer: null
    };
  },
  mounted() {
    this.count();
  },
  destroyed() {
    clearInterval(this.timer);
  },
  methods: {
    count() {
      this.timer = setInterval(() => {
        this.countDown = this.countDown - 1;
        if (this.countDown === 0) {
          this.show = false;
        }
      }, 1000);
    },
    closeTimer() {
      clearInterval(this.timer);
      this.show = false;
    }
  }
};
</script>

<style lang="scss">
.im-top {
  position: fixed;
  background: #fef8ef;
  width: 100%;
  height: 40px;
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
  color: #ff6a0d;
  font-size: 13px;
  z-index: 99999;
  box-sizing: border-box;
  .close {
    font-family: PingFangSC-Regular, PingFang SC;
    font-weight: 400;
    color: rgba(102, 102, 102, 1);
    line-height: 17px;
    margin-left: 4px;
  }
}
</style>
